package com.zkingsoft.zkingbase.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListView;

import com.zkingsoft.zkingbase.R;
import com.zkingsoft.zkingbase.adapter.GoodsListAdapter;
import com.zkingsoft.zkingbase.base.BaseActivity;
import com.zkingsoft.zkingbase.bean.Goods;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class GoodsActivity extends BaseActivity
{

    @BindView(R.id.lv)
    ListView lv;
    @BindView(R.id.sl)
    SwipeRefreshLayout sl;

    private GoodsListAdapter adapter;
    private List<Goods> list;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        list = new ArrayList<>();
        for (int i = 0; i < 20; i++)
        {
            Goods g = new Goods();
            g.setId(i);
            g.setDescription("超亮led灯带，买一送100,绝对惊艳，活动还剩3天");
            g.setImgUrl("https://img.alicdn.com/bao/uploaded/i2/2098025659/TB2Lk_tXX_AQeBjSZFyXXb1bXXa_!!2098025659.jpg_b.jpg");
            g.setPrice(12.5f);
            list.add(g);
        }
        adapter = new GoodsListAdapter(this, list);
        View v = View.inflate(this, R.layout.loading_more, null);
        lv.addFooterView(v);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {   
                    startActivity(new Intent(GoodsActivity.this, SBActivity.class));
            }
        });
        lv.setOnScrollListener(new AbsListView.OnScrollListener()
        {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState)
            {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
            {

            }
        });
    }

    @Override
    public int getContentView()
    {
        return R.layout.activity_goods;
    }
}
